function saveLog_dev(logStr, lastCall, skip)
  % Writes activity/status log to text file logFile and pushes
  % it into database DB; logStr empty clears currentCastGUIDs of extant 
  % log entries; lastCall non-empty signifies this is the last attempt
  % to update the logs before exiting; skip indicates an output mode 
  % (DB or logFile) to skip
  %
  % Author: David Goldsmith, Wash. State Dept. of Ecology, dgol461@ecy.wa.gov
  % Release date: N/A
  %
  % TODO: add error handling!
  
    global DB logFile currentCastGUIDs eN
    persistent q U
    
    if nargin < 3
        skip = '';
    end
  
    if nargin < 2
        lastCall = '';
    end
  
    if isempty(q)
        q = query_dev(DB, struct('tbls', {{'CastRaw'}},...
                                 'cols', {{'ProcLogFileBLOB'}}));
    end
  
    if isempty(U)
        U = Update_dev(DB, struct('tbls', {{'CastRaw'}},...
                                  'cols', {{'ProcLogFileBLOB'}}));
    end

    msg = {};
  % For each CastGUID in currentCastGUIDs
    for i=1:numel(currentCastGUIDs)
        where = ['CastGUID=''' currentCastGUIDs{i} ''''];
        if isempty(logStr) % Clear extant log strings
            U.setPropVals('data', struct('ProcLogFileBLOB', 'null'))
            U.setPropVals('where', {where})
            U.submitStatement
            if ~isempty(U.errCode)
                msg{end+1} = ['Error clearing CastGUID ' currentCastGUIDs{i}...
                              '''s log entry; the first part of this Cast'...
                              'GUID''s log entry is probably obsolete.  '];
                U.errCode = {};
            end
        elseif ~strcmp(skip, 'DB')
          % Retrieve the current log entry
            q.setPropVals('where', {where})
            q.submitStatement
          % If successful
            if isempty(q.errCode)
                curLog = {regexprep(q.result{:}, 'null', '')}; 
                  % {} ensures curLog will be a cell array after next line
              % Trim the old logStr, add back two spaces, & append the new logStr
                curLog = [strtrim(curLog) '  ' logStr];
              % Update the updater
                U.setPropVals('data', struct('ProcLogFileBLOB', [curLog{:}]))
                U.setPropVals('where', {where})
              % Push the new log string
                U.submitStatement
              % If unsuccessful
                if ~isempty(U.errCode)
                    msg{end+1} = ['Error updating CastGUID ' currentCastGUIDs{i}...
                                  '''s log entry; the current log string: "'...
                                  logStr '" not appended to it in the DB.  '];
                    U.errCode = {};
                end
            else % if unsuccessful retrieving current log
                msg{end+1} = ['Error retrieving CastGUID ' currentCastGUIDs{i}...
                              '''s log entry; the current log string: "'...
                              logStr '" not appended to it in the DB.  '];
                q.errCode = {};
            end
        end
    end
    
    if ~isempty(msg)
        logStr = [logStr [msg{:}]];
        eN.send = 1;
    end
    
    if isempty(logStr)
        return
    end
    
    if isa(logFile, 'fileWrapper_dev') && ~strcmp(skip, 'LF')
      % Write the log to logFile
        logFile.checkedfprint(logStr);    
        if ~isempty(logFile.err)
            logStr = [logStr [logFile.err{:}]];
            eN.send = 1;
        end
    end
    
    if ~isempty(lastCall) && ~isempty(logStr)
        if iscellstr(logStr)
            eN.appendMsg([logStr{:}])
        else
            eN.appendMsg(logStr)
        end
    end    
    
end